<template>
    <div class="page">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-profile"></i> 课程评价 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="back" 
            style="padding: 30px;
                background: #fff;
                border: 1px solid #ddd;
                border-radius: 5px;">
            <el-table
                :data="tableCourses"
                border
                style="width: 100%"
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                >
                <el-table-column prop="course_id" label="课程号" width="100"></el-table-column>
                <el-table-column prop="course_name" label="课程名" width="200"></el-table-column>
                <el-table-column prop="course_nature" label="课程类型" width="90">
                    <!-- <el-tag type="warning"></el-tag> -->
                </el-table-column>
                <el-table-column prop="course_college" label="授课学院" width="180"></el-table-column>
                <el-table-column prop="course_teacher" label="主讲老师" width="90"></el-table-column>
                <el-table-column prop="course_credit" label="学分" width="90"></el-table-column>
                <el-table-column prop="course_time" label="学时" width="90"></el-table-column>
                <el-table-column
                    prop="course_address"
                    label="上课地点"
                    :show-overflow-tooltip="true"
                ></el-table-column>
                <el-table-column prop="course_year" label="开课年份" width="90"></el-table-column>
                <!-- <el-table-column prop="grade" label="面向年级" width="90"></el-table-column> -->
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" @click="handleComment(scope.$index, scope.row)">评价</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 评价对话框 -->
        <el-dialog title="课程评价" :visible.sync="commentVisible">
            <el-form :model="form" label-width="70px">
                <el-form-item label="输入评价">
                <el-input type="textarea" :rows="3" v-model="form.comment" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="commentVisible=false">取消</el-button>
                <el-button type="primary" @click="commitComment()">提交</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { getRequest, postRequest } from '@/api/index';

export default {
    name: 'StuComment',
    components: {},
    data() {
        return {
            commentVisible: false,
            id:39,
            form:{
                comment:'',
            },
            tableCourses: []
        };
    },
    created() {
        this.getCoursesData();
    },
    methods: {
        // 获取课程列表
        getCoursesData(){
            getRequest('/login/student/change/getselected').then(res => {
                if (res.code == 200) {
                    console.log('获取本学期课程')
                    console.log(res)
                    this.tableCourses=res.data
                }
            });
        },
        handleComment(index,row){
            // 防止同步修改
            this.form = JSON.parse(JSON.stringify(row));
            this.commentVisible=true;
        },
        handleComment(index,row){
            this.commentVisible=true
            this.id=row.course_id
        },
        // 提交评价
        commitComment(){
            postRequest('/login/student/change/stucomment',
            {
                f_begin_class:this.id,
                f_comment:this.form.comment
            }).then(res => {
                console.log(res);
                if (res.code == 200) {
                    this.$message.success('提交评价成功!');
                } else if (res.code == 402) {
                    this.$message.error(res.msg);
                }
            }, err => {
                this.$message.error('提交评价失败！');
            })
            this.commentVisible=false;
        }
    },
};
</script>

<style>
.hide .el-upload--picture-card {
    display: none;
}
.search {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-bottom: 5px;
    padding-top: 5px;
    border-bottom: 1px solid #cfcfcf;
    border-bottom: 1px solid #7c7a7a;
}

.lesson_name {
    width: 20%;
    padding-left: 10px;
    padding-right: 10px;
}
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.mr10 {
    margin-right: 10px;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
.btn-add {
    float: right;
}
</style>
